import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
// 引入path模块
import path from 'path';

export default defineConfig(({ mode }) => {
    // 加载环境变量
    const env = loadEnv(mode, process.cwd());

    console.log(env.VITE_API_URL ); // 输出环境变量的值
    return {
        plugins: [vue()],
        resolve: {
            alias: {
                '@': path.resolve(__dirname, 'src')
            }
        },
        server: {
            host: '0.0.0.0',
            proxy: {
              '/api': {
                target: env.VITE_API_URL,
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, ''),
              },
            },
          },
      define: {
        // 将变量注入代码中供运行时使用
        __API_URL__: JSON.stringify(env.VITE_API_URL),
      },
    };

  });



